package stackexchange.analyzer.evaluator;

import stackexchange.User;

public class VBREvaluator extends ExpertEvaluator {

	@Override
	double calculateExpertScore(User user) {
		double up = user.getUpVotes();
		double down = user.getDownVotes();
		double total = user.getUsersAnswers().size();
		double votes = (((up - down) / (up + down)) + up / total) / total;

		int nAcceptedAnswers = 0;
		int nBestAnswers = 0;
		for (int i = 0; i < user.getUsersAnswers().size(); i++) {
			if (user.getUsersAnswers().get(i).isAnAcceptedAnswer()) {
				nAcceptedAnswers++;
			}
			if (user.getUsersAnswers().get(i).isAnMostRatedAnswer()) {
				nBestAnswers++;
			}
		}

		double best = nBestAnswers / total;

		double rating = nAcceptedAnswers / total;

		return votes + best + rating;
	}

}
